{$CLEO .cs}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "GasCanQ"

// By ArtemQa146

const
    car_gasoline = 0@
    find = 31@
    station = 30@
    blip_icon_txd = 29@
    price = 28@
    PLAYER_TANK = 27@
    Enb_vis = 26@
    icon_pos_x = 25@
    icon_pos_y = 24@
    icon_size = 23@
    key_1 = 22@
    key_2 = 21@
    scene = 20@
    render_1 = 19@
end

0AF0: 0@ = read_int_from_ini_file "cleo\Gasoline Mod.ini" section "Fuel canister" key "Enable"
if
    0@ == 0
then
    0A93: terminate_this_custom_script
end

0AF0: Enb_vis = read_int_from_ini_file "cleo\Gasoline Mod.ini" section "Visual Settings" key "Enable Indicator"
0AF2: icon_pos_x = read_float_from_ini_file "cleo\Gasoline Mod.ini" section "Fuel canister" key "Icon Position X"
0AF2: icon_pos_y = read_float_from_ini_file "cleo\Gasoline Mod.ini" section "Fuel canister" key "Icon Position Y"
0AF2: icon_size = read_float_from_ini_file "cleo\Gasoline Mod.ini" section "Fuel canister" key "Icon Size"
0AF0: key_1 = read_int_from_ini_file "cleo\Gasoline Mod.ini" section "Fuel canister" key "Key 1"
0AF0: key_2 = read_int_from_ini_file "cleo\Gasoline Mod.ini" section "Fuel canister" key "Key 2"
0AF0: scene = read_int_from_ini_file "cleo\Gasoline Mod.ini" section "Fuel canister" key "Scene"

0390: load_txd_dictionary "GSMOD"
038F: load_texture "GSSB" as 1  // Load dictionary with 0390 first
0E3C: get_texture_from_sprite 1 store_to blip_icon_txd
0391: release_textures

price = 150
PLAYER_TANK = false


while true
wait 500
    if
        player.Defined(0)
    then
        
        if and
            PLAYER_TANK == true
            00DF:   actor $PLAYER_ACTOR driving
        then
            03C0: car_gasoline = actor $PLAYER_ACTOR car
            0A97: 1@ = car car_gasoline struct
            0D4E: 2@ = struct 1@ offset 0x8 size 1
            if
                08B7:   test 2@ bit 1 //   
            then
                0E12: get_vehicle Car_gasoline subclass_to 1@
                if or
                    1@ == 0
                    1@ == 1
                    1@ == 2
                    1@ == 9
                    1@ == 5
                then
                
                    2@ = 200
                    3@ = 100
                
                    repeat
                    wait 0

                        if
                            056E:   car car_gasoline defined
                        then
                            if
                                00DB:   actor $PLAYER_ACTOR in_car car_gasoline
                            then
                                if and
                                    is_hud_visible
                                    Enb_vis == 1
                                then
                                    0E1E: draw_texture_plus blip_icon_txd event 1 pos icon_pos_x icon_pos_y size icon_size icon_size angle 0.0 depth 0 1 0 0 rgba 200 2@ 2@ 3@
                                end
                                
                                0E12: get_vehicle Car_gasoline subclass_to 1@
                                if and
                                    01C1:   car Car_gasoline stopped
                                    00E1:   player 0 pressed_key key_1
                                    00E1:   player 0 pressed_key key_2
                                then
                                    2@ = 20
                                    3@ = 230
                                    if
                                        timera > 2000
                                    then
                                        if or
                                            1@ == 0
                                            1@ == 9
                                        then
                                            if
                                                scene == 1
                                            then
                                                0AAA: 1@ = get_script_struct_named "GasST"
                                                0AAA: 2@ = get_script_struct_named "GasSTB"
                                                if and
                                                    1@ == 0
                                                    2@ == 0
                                                then
                                                    PLAYER_TANK = false
                                                    0A97: 1@ = car car_gasoline struct
                                                    0E28: write_struct 1@ offset 0x9 size 4 value 1000
                                                    1@ = true
                                                    0A92: stream_custom_script "GasStationB.qa" 1@ Car_gasoline
                                                    repeat
                                                    wait 300
                                                    0AAA: 1@ = get_script_struct_named "GasSTB"
                                                    until 1@ == 0
                                                end
                                            else
                                                PLAYER_TANK = false
                                                0A97: 1@ = car car_gasoline struct
                                                0E28: write_struct 1@ offset 0x9 size 4 value 1000
                                            end
                                            break
                                        else
                                            PLAYER_TANK = false
                                            0A97: 1@ = car car_gasoline struct
                                            0E28: write_struct 1@ offset 0x9 size 4 value 1000
                                            break
                                        end
                                    end
                                else
                                    timera = 0
                                    2@ = 200
                                    3@ = 100
                                end
                            else
                                break
                            end
                        else
                            break
                        end
                    
                    until not player.Defined(0)
                end
            end
            
        else
            if and
                80DF:   not actor $PLAYER_ACTOR driving
                PLAYER_TANK == false
            then
                find = 0
                5@ = false
                
                04C4: store_coords_to 1@ 2@ 3@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
                0AA7: call_function_return 0x5693F0 num_params 9 pop 9 0 0 0 0 1 0 10.0 1@v 3465 station
                if
                    station > 0
                then
                    0EEE: get_entity_coordinates station store_to 1@ 2@ 3@
                    if
                        0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1@ 2@ 3@ radius 3.0
                    then
                        5@ = true
                    end
                end
                
                if
                    5@ == false
                then
                    while get_any_object_no_save_recursive find progress_to find object_to station
                        if or
                            09CC:   object station model_is 1686
                            09CC:   object station model_is 1676
                            09CC:   object station model_is 3465
                            09CC:   object station model_is 1244
                        then
                            if
                                0EE6: locate_char_distance_to_object $PLAYER_ACTOR object station radius 3.0
                            then
                                0400: store_coords_to 1@ 2@ 3@ from_object station with_offset 0.0 0.0 0.0
                                5@ = true
                                break
                            end
                        end
                    end
                end

                if
                    5@ == true
                then
                    0513: show_text_box_1number 'gasqa' number price  // ~k~~VEHICLE_ENTER_EXIT~ Use Slot Machine $~1~

                    repeat
                    wait 0
                        if and
                            02A0:   actor $PLAYER_ACTOR stopped
                            00E1:   player 0 pressed_key 15
                            80DF:   not actor $PLAYER_ACTOR driving
                            03EE:   player $PLAYER_CHAR controllable
                        then
                            if
                                010A:   player $PLAYER_CHAR money > price
                            then
                                03E6: remove_text_box
                                0085: 1@ = price // (int)
                                1@ *= -1
                                0109: player $PLAYER_CHAR money += 1@
                                06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 1
                                0687: clear_actor $PLAYER_ACTOR task
                                07CC: set_player $PLAYER_CHAR can_enter_exit_vehicles 0
                                01B4: set_player $PLAYER_CHAR can_move 0

                                016A: fade 0 time 500

                                wait 800

                                if
                                    scene == 1
                                then

                                    repeat
                                    wait 0
                                    04ED: load_animation  "gasstation"
                                    until 04EE:   animation "gasstation" loaded
                                    0812: AS_actor $PLAYER_ACTOR perform_animation "petrolBuy" IFP "gasstation" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 1 time -1  // versionB
                                    04EF: release_animation "gasstation"

                                    04C4: store_coords_to 1@ 2@ 3@ from_actor $PLAYER_ACTOR with_offset 0.7 1.0 0.3
                                    04C4: store_coords_to 4@ 5@ 6@ from_actor $PLAYER_ACTOR with_offset 0.0 0.2 0.35
                                    015F: set_camera_position 1@ 2@ 3@ rotation 0.0 0.0 0.0
                                    0160: set_camera_point_at 4@ 5@ 6@ switchstyle 2

                                    016A: fade 1 time 500

                                    wait 1300
                                    0AF0: 1@ = read_int_from_ini_file "cleo\Gasoline Mod.ini" section "Models" key "PetrolCanB"
                                    0F02: create_render_object_to_char_bone_from_special $PLAYER_ACTOR special_model 1@ bone 24 offset 0 0 0 rotation 0 0 0 store_to render_1

                                    wait 1600

                                    016A: fade 0 time 500

                                    wait 500

                                    0E2F: delete_render_object render_1
                                    0687: clear_actor $PLAYER_ACTOR task
                                    02EB: restore_camera_with_jumpcut
                                end

                                wait 300

                                07CC: set_player $PLAYER_CHAR can_enter_exit_vehicles 1
                                06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 0
                                01B4: set_player $PLAYER_CHAR can_move 1
                                016A: fade 1 time 500

                                PLAYER_TANK = true

                                wait 500
                                0512: show_permanent_text_box 'gasq2'
                                wait 2000

                                break
                            else
                                00BC: show_text_highpriority GXT 'gasq3' time 2000 flag 1
                            end
                        end
                    until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1@ 2@ 3@ radius 3.0
                    03E6: remove_text_box
                end
            end
        end
    end
end